package cn.itsource;

import com.netflix.loadbalancer.RandomRule;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.SpringCloudApplication;
import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.context.annotation.Bean;
import org.springframework.web.client.RestTemplate;

//@SpringBootApplication
//@EnableEurekaClient
//@EnableCircuitBreaker // 开启断路器
@SpringCloudApplication // 上面三个注解的复合注解
public class OrderStart {

    public static void main(String[] args) {
        SpringApplication.run(OrderStart.class,args);
    }

    // 启动的时候，把RestTemplate 实例注册到SpringBoot 容器中
    //  RestTemplate 需要有负载均衡的功能
    @Bean
    @LoadBalanced
    public RestTemplate getRestTeamplate(){
        return  new RestTemplate();
    }

    // 配置负载均衡的算法（随机）
//    @Bean
//    public RandomRule randomRule(){
//        return new RandomRule();
//    }
}
